package project.Service.Impl;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import project.Pojo.Chat.AI.DeepSeekRequest;
import project.Pojo.Chat.AI.DeepSeekResponse;

import java.util.ArrayList;
import java.util.List;

@Service
public class DeepSeekService {

    String url = "https://api.deepseek.com/chat/completions";
    String key = "sk-3a98dd4d1f07415ba8a64f6816ddaf82";


    public String call(String message) {

        DeepSeekRequest request = new DeepSeekRequest();
        request.setModel("deepseek-chat");
        DeepSeekRequest.Message message1 = new DeepSeekRequest.Message(message, "user");
        List<DeepSeekRequest.Message> list = new ArrayList<>();
        list.add(message1);
        request.setMessages(list);

        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add("Accept", "application/json");
        headers.add("Authorization", "Bearer " + key);

        HttpEntity<DeepSeekRequest> entity = new HttpEntity<>(request, headers);

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<DeepSeekResponse> exchange = restTemplate.exchange(url, HttpMethod.POST, entity, DeepSeekResponse.class);
        String result = exchange.getBody().getChoices().get(0).getMessage().getContent();
        return result;
    }


}
